#include <bits/stdc++.h>
using namespace std;
int n,a[10005];
bool color[10005];
int ans = 0;
void dfs(int now,int x){
  //  cout << now << ' ' << x << endl;
    if (now > n) return ;
    if (now == n){
      //  cout << now << ' ' << x << endl;
        int res = 0;
        for (int i = 1;i <= n;i++){
            color[i] = (1 << i) & x;
    //        cout << i <<  " : " << color[i] << endl;
        }
        for (int i = 1;i <= n;i++){
            for (int j = i - 1;j >= 1;j--){
                if (color[i] == color[j]){
                    res += (a[i] == a[j] ? a[i] : 0);
                    break;
                }
            }
        }
        ans = max(ans,res);
        return ;
    }
    dfs(now + 1,x << 1);
    dfs(now + 1,x << 1 | 1);
}
void solve(){
    ans = 0;
    cin >> n;
  //  cout << n << endl;
    for (int i = 1;i <= n;i++) cin >> a[i];
    if (n >= 40){
        cout << 0 << endl;
        return ;
    }
    dfs(0,0);
    cout << ans << endl;
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin >> t;
    while(t--){
        solve();
      //  cout << 1 << endl;
    }
    return 0;
}
